<?php
namespace Admin\Model;

use Think\Model;

class TeachplanModel extends Model {

    public function getTeachplanByWhere($where,$limit='') {
        is_null($where) && $where = '';
        return $this->where($where)->limit($limit)->select();
    }


    public function getAllTeachplanByTid($tid) {
        return $this->where('teacher_id = '.$tid)->select();
    }



    public function getSidsArrByTid($id) {
        $idsStr = $this->where('id = '.$id)->getField('student_ids');
        return explode(',',$idsStr);
    }


    public function _get($id) {
        return $this->find($id);
    }


    public function _add($data) {
        $map['name'] = $data['name'];
        $map['term_id'] = $data['term_id'];
        $map['teacher_id'] = $data['teacher_id'];
        //$this->getLastInsID()
        $res = $this->where($map)->find();
        if (!empty($res)) return '101001';

        $flag = $this->add($data);
        if ($flag !== false) return '000000';
        return '111111';
    }


    public function _save($data) {
        $map['name'] = $data['name'];
        $map['term_id'] = $data['term_id'];
        $map['teacher_id'] = $data['teacher_id'];
        $map['id'] = array('neq',$data['id']);
        //$this->getLastInsID()
        $res = $this->where($map)->find();
        if (!empty($res)) return '101001';

        $flag = $this->save($data);
        if ($flag !== false) return '000000';
        return '111111';
    }


    public function _del($id) {
        $flag = $this->delete($id);
        if ($flag !== false) return '000000';
        return '111111';
    }

}